﻿using UnityEngine;
using System.Collections;
using MyAssetBundles;

public abstract class MyAssetBundlesModel : MyAssetBundlesMono {
    public override string serverUrl
    {
        get {
            return MyAssetBundlesConfig.AssetBundlesServerUrl;
        }
    }

    public override string localPath
    {
        get {
            return MyAssetBundlesConfig.AssetBundlesPath;
        }
    }

    public override string versionsName
    {
        get {
            return MyAssetBundlesConfig.VersionsFileName;
        }
    }

    public override IEnumerator Init ()
    {
        Debug.Log("asset bundles model init");
        yield return new WaitForEndOfFrame();
    }

    public override IEnumerator Complete ()
    {
        yield return new WaitForEndOfFrame();
    }

    public override void Clean ()
    {

    }
    
    public override void DownloadProgress (ProgressTarget target)
    {
        Debug.Log(string.Format("download curr: {0}, total: {1}, progress: {2}%",
            target.processNum,
            target.totalNum,
            target.progress * 100
            ));
    }

    public override void DecompressProgress (ProgressTarget target)
    {
        Debug.Log(string.Format("decompress curr: {0}, total: {1}, progress: {2}%",
            target.processNum,
            target.totalNum,
            target.progress * 100
            ));
    }

    public override void UnpackProgress (ProgressTarget target)
    {
        Debug.Log(string.Format("unpack file name: {3}, curr: {0}, total: {1}, progress: {2}%",
            target.processNum,
            target.totalNum,
            target.progress * 100,
            target.fileNameCurr
            ));
    }
    
    protected IEnumerator ResetAssetBundles ()
    {
        yield return MyAssetManager.Instance.Reset();
    }

    protected IEnumerator ResetDependencies ()
    {
        if (_assetBundlesNameList.Count > 0)
            yield return MyAssetManager.Instance.ReloadDependencies(_assetBundlesNameList);
        yield return new WaitForEndOfFrame();
    }
}
